import moment from 'moment'
import { date2str } from '@/tools/date.tool'

function formatNoticeTitle(row, column) {
  const item = row[column.property]
  if (item === '3') {
    return '外网公告'
  }
  return '未知'
}

function formatIsTop(row, column) {
  const item = row[column.property]
  if (item === 1) {
    return '是'
  }
  else {
    return '否'
  }
}

function formatStatus(row, column) {
  const item = row[column.property]
  if (item === 0) {
    return '是'
  }
  else {
    return '否'
  }
}

function formatDate(row, column) {
  const item = row[column.property]
  var date = new Date(item);
  date.setHours(date.getHours() + 8);
  return item ? moment(date).format('YYYY-MM-DD HH:mm:ss') : ' -- ';
}

export default [
  {
    type: 'index',
    minWidth: '50',
    label: ''
  },
  {
    prop: 'noticeTitle',
    minWidth: '150',
    label: '公告标题',
  },
  {
    prop: 'noticeType',
    minWidth: '150',
    label: '公告类型',
    formatter: formatNoticeTitle
  },
  {
    prop: 'isTop',
    minWidth: '80',
    label: '是否置顶',
    formatter: formatIsTop
  },
  {
    prop: 'status',
    minWidth: '80',
    label: '是否有效',
    formatter: formatStatus
  },
  {
    prop: 'publisherName',
    minWidth: '100',
    label: '发布人'
  },
  {
    prop: 'publishTime',
    minWidth: '120',
    label: '发布日期',
    formatter: formatDate
  },
  {
    prop: 'gmtModify',
    minWidth: '120',
    label: '记录时间',
    formatter: formatDate
  },
  {
    fixed: 'right',
    minWidth: '120',
    label: '操作',
    slotName: 'operation'
  }
]
